//
//  DCRichFileTransferModule.m
//  LibWeexDCFileTransfer
//
//  Created by simple on 2019/4/10.
//  Copyright © 2019年 simple. All rights reserved.
//

#import "DCRichFileTransferModule.h"
#import "WXUtility.h"
#import "Utils.h"

@interface DCRichFileTransferModule()

@end
@implementation DCRichFileTransferModule


@synthesize weexInstance;

WX_EXPORT_METHOD(@selector(getfilelist:callback:)) 


- (instancetype)init
{
    if (self = [super init]) {
        
    }
    return self;
}

- (void)_getFileList:(NSDictionary *)options callback:(WXModuleKeepAliveCallback)callback
{
    /*
    NSString *path = [Utils newDirector];
    NSError *error = nil;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSArray *fileList = [fileManager contentsOfDirectoryAtPath:path error:&error];
    NSMutableArray *dirArray = [[NSMutableArray alloc] init];
    BOOL isDir = TRUE;
    //在上面那段程序中获得的fileList中列出文件夹名
    NSMutableString *files = [[NSMutableString alloc]init];
    for (NSString *file in fileList) {
        NSString *filePath = [[Utils newDirector] stringByAppendingPathComponent:file];
        [fileManager fileExistsAtPath:filePath isDirectory:(&isDir)];
        if (!isDir) {
            [dirArray addObject:filePath];
            [files appendString:filePath];
        }
        isDir = TRUE;
    }
     */
    NSString *path =  [[NSUserDefaults standardUserDefaults] stringForKey:@"NewFilePath"];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"NewFilePath"];
    if (callback) {
        callback(@{@"path":path?path:@""},YES);
    }
}


#pragma mark - Export Method


- (void)getfilelist:(NSDictionary *)options callback:(WXModuleKeepAliveCallback)callback
{
    [self _getFileList:options callback:callback];
}


@end
